//
//  GYGoodsInfo.m
//  GoodLuck
//
//  Created by apple on 2018/3/6.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYGoodsInfo.h"
#import "GYNetWorkTools.h"

@implementation GYGoodsInfo

+ (void)loadGoodsInfo:(NSString *)goods_id finish:(void (^)(GYGoodsInfo * _Nullable, NSError * _Nullable))finish {
    [GYNetWorkTools requestGoodsDetails:goods_id success:^(NSDictionary *obj) {
        int code = [[obj objectForKey:@"code"] intValue];
        NSDictionary *datas = [obj objectForKey:@"datas"];
        if (code == 200) {
            NSDictionary *goods_info = [datas objectForKey:@"goods_info"];
            GYGoodsInfo *goodsInfo = [[GYGoodsInfo alloc] initWithDic:goods_info];
            finish(goodsInfo,nil);
        }else {
            NSLog(@"网络加载出错===%@",[datas objectForKey:@"error"]);
        }
    } error:^(NSError *error) {
        finish(nil,error);
       NSLog(@"laodGoodsetailFailed====%@",error);
    }];
}


- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    //NSLog(@"key =====%@",key);
}

- (NSString *)description {
    NSArray *keys = @[@"goods_name",@"is_favorate",@"goods_price",@"goods_url"];
    
    return [NSString stringWithFormat:@"%@",[self dictionaryWithValuesForKeys:keys]];
}


@end
